package huawei.exam1;

import java.util.Scanner;

/**
 * @author : Rookie
 * @description : 进制转换
 * @date : 2022/12/11
 */
public class HJ5 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String str = scanner.nextLine();
            System.out.println(covertBaseOfTen(str));
        }
    }

    /**
     * 16进制数转10进制
     * @param hexNum
     * @return
     */
    private static String covertBaseOfTen(String hexNum) {
        String num = hexNum.substring(2);
        int baseOfTenNum = 0;
        for (int i = 0; i < num.length(); i++) {
            int tempNum = covert(num.charAt(i));
            baseOfTenNum += tempNum * Math.pow(16,num.length() - i - 1);
        }
        return String.valueOf(baseOfTenNum);
    }

    private static int covert(char num) {
        int tempNum = 0;
        switch (num) {
            case 'A' : tempNum = 10;
                    break;
            case 'B' : tempNum = 11;
                break;
            case 'C' : tempNum = 12;
                break;
            case 'D' : tempNum = 13;
                break;
            case 'E' : tempNum = 14;
                break;
            case 'F' : tempNum = 15;
                break;
            default: tempNum = Integer.parseInt(String.valueOf(num));
                break;
        }
        return tempNum;
    }
}
